package com.school.revervationSys.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.school.revervationSys.dto.IdDto;
import com.school.revervationSys.dto.UserDto;
import com.school.revervationSys.entity.TestManage;
import com.school.revervationSys.entity.User;
import com.school.revervationSys.mapper.TestManageMapper;
import com.school.revervationSys.service.TestManagerService;
import com.school.revervationSys.utils.BaseResponse;
import com.school.revervationSys.utils.ErrorCode;
import com.school.revervationSys.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/testManage")
public class TestManageController {

    @Autowired
    private TestManagerService testManagerService;
    @PostMapping("/addTestManage")
    public BaseResponse addTestManage(@RequestBody TestManage testManage){

        boolean b = testManagerService.addTestManager(testManage);
        if(b){
            return ResultUtils.success("新增成功");
        }
        return ResultUtils.error(ErrorCode.OPERATION_FAILED,"操作失败");
    }
    @PostMapping("/updateTestManage")
    public BaseResponse updateUser(@RequestBody TestManage testManage){

        boolean b = testManagerService.updateTestManage(testManage);
        if(b){
            return ResultUtils.success("修改成功");
        }
        return ResultUtils.error(ErrorCode.OPERATION_FAILED,"修改失败");
    }

    @GetMapping("/delTestManage")
    public BaseResponse delTestManage(Integer testManageId){

        boolean b = testManagerService.delete(testManageId);
        if(b){
            return ResultUtils.success("删除成功");
        }
        return ResultUtils.error(ErrorCode.OPERATION_FAILED,"删除失败");
    }
    @PostMapping("/batchDelTestManage")
    public BaseResponse batchDelTestManage(@RequestBody IdDto param){

        boolean b = testManagerService.batchDelete(param.getIds());
        if(b){
            return ResultUtils.success("批量删除成功");
        }
        return ResultUtils.error(ErrorCode.OPERATION_FAILED,"批量删除失败");
    }

    @GetMapping("/testManageList")
    public BaseResponse testManageList(String title,Integer pageNo,Integer pageSize){
        PageHelper.startPage(pageNo,pageSize);
        List<TestManage> list = testManagerService.testManageList(title);
        PageInfo<TestManage> userPageInfo = new PageInfo<>(list);
        return ResultUtils.success(userPageInfo);
    }



}
